<template>
	<view>
		<view class="content">
			<u-parse :content="detailData.riskNotice"></u-parse>
		</view>
		<view class="bottom-view">
			<view class="btn" :style="{
				color:type === 'wait' ? 'rgba(35,35,35,0.26)' : '',
				background:type === 'wait' ? '#F3F3F3' : '',
			}" @click="navToBookingAndPayment">{{btnText}}</view>
		</view>
	</view>
</template>

<script>
	import * as medicalProjects from '../../common/api/medicalProjects.js'
	export default {
		data() {
			return {
				type:"wait",
				btnText:'已阅读并同意（3s）',
				timer:null,
				timerNumber:3,
				value:'',
				uid:'',
				addType:'',
				contactName:'',
				detailData:{}
			}
		},
		onLoad(opt) {
				this.contactName = opt.contactName

			if(opt.uid){
				this.uid = opt.uid
			}
			if (opt.hospitalUid) {
				this.hospitalUid = opt.hospitalUid;
			}
			if(opt.addType){
				this.addType = opt.addType
			}
			if(opt.type){
				this.value = opt.type
			}
			this.getData()
			this.init()
		},
		methods: {
			getData() {
				const param = {
					uid: this.uid
				}
				medicalProjects.queryById(param).then(result => {
					this.detailData = result.data.data
				}).catch(error => {
					console.log(error);
				})
			},
			init(){
				this.timer = setInterval(()=>{
					if(this.timerNumber <= 0){
						if(this.timer){
							clearInterval(this.timer)
							this.timer = null
						}
						this.type = 'done'
						this.btnText = `已阅读并同意`
					}else{
						this.btnText = `已阅读并同意（${this.timerNumber}s）`
						this.timerNumber--
					}
				},1000)
			},
			navToBookingAndPayment(){
				if(this.type === 'wait'){
					return
				}
				if(this.addType === 'add_cart'){
					this.$store.commit("page/setPageInfo", {
						hasRead: true
					})
					uni.navigateBack()
				}else if(this.addType === 'book_now'){
					uni.redirectTo({
						url:"/patientAppPages/pages/bookingAndPayment/bookingAndPayment?uid="+this.uid+'&hospitalUid=' +this.hospitalUid+'&contactName=' +this.contactName+"&type="+this.value  
					})
				}
			}
		}
	}
</script>
<style>
	page {
		background-color: white;
	}
</style>
<style lang="scss" scoped>
	page{
		background: white;
	}
	.content{
		padding: 44rpx;
		color: #232323;
		font-size: 32rpx;
		padding-bottom: 140rpx;
	}
	.bottom-view{
		width: 100%;
		position: fixed;
		bottom: 0;
		height: 120rpx;
		background: white;
		padding-left: 30rpx;
		padding-right: 30rpx;
		box-sizing: border-box;
		display: flex;
		align-items: center;
		justify-content: center;
		.btn{
			width: 100%;
			height: 88rpx;
			background: #0BC5AE;
			color: white;
			font-size: 30rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			border-radius: 48rpx;
		}
	}
</style>
